<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    手机号码: <input type="number"> <button>发送验证码</button>
    <script>
        /* 
            需求:
                1. 点击按钮，开启倒计时。按钮禁用。
                2. 倒计时结束，按钮恢复
        */
        let btn = document.querySelector('button');
        btn.addEventListener('click', function () {
            let index = 3;
            this.disabled = true;
            btn.innerHTML = index;
            
            let timer = setInterval(() => {
                index--;
                btn.innerHTML = index;
                if (index == 0) {
                    clearInterval(timer);
                    this.disabled = false;
                    this.innerHTML = '发送验证码';
                }
            }, 1000);
        });

    </script>
</body>

</html>